def init(n): 
    a = [[0 for i in range(0,n)] for j in range(0,n)]
    return a[:]
    
def merge(n,a):
    m = n // 2;
    for i in range(0,m):
        for j in range(0,m):
            a[i][j+m]=a[i][j]+m;  
            a[i+m][j]=a[i][j+m];  
            a[i+m][j+m]=a[i][j];  

def arrangement(n,a):
    if n==1:
        a[0][0]=1
        return
    arrangement(n//2,a);  
    merge(n,a);   

def main():
    n = int(input())
    a = init(n)
    arrangement(n,a)
    for i in range(0,n):
        for j in range(0,n):
            print(a[i][j],end = ' ')
        print()
        
main()